package com.spring.lifecycle.controller;

import com.spring.lifecycle.service.BoyService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.stereotype.Controller;

@Controller
public class BoyController {
    //如果在ioc容器中找到了组件则注入进去，如果没有则不许装配，如果required=true则必须装配
    @Autowired(required = false)
    //@Qualifier("boyService3")  //指定bean的id
    private BoyService boyService;  //将已有的Service类装配到Controller

    public void print(){
        System.out.println(boyService);
    }

    @Override
    public String toString() {
        return "BoyController{" +
                "boyService=" + boyService +
                '}';
    }
}
